package org.mzx.shortLink.adminn.service.handler.chain.userRegister;

import lombok.RequiredArgsConstructor;
import org.mzx.shortLink.adminn.dto.Request.TUserDtoReq;
import org.mzx.shortLink.starter.convention.Exception.ServiceException;
import org.redisson.api.RBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * @author mazhenxi
 * @date 2025/4/24
 * @desc 检查用户名是否已经存在
 */
@Component
@RequiredArgsConstructor
public class userRegisterCheckUserName implements userRegisterChain{

    @Autowired
    @Qualifier("userRegisterCachePenetrationBloomFilter")
    private RBloomFilter<String> userRegisterCachePenetrationBloomFilter;

    @Override
    public void handler(TUserDtoReq requestParam) {
        if(userRegisterCachePenetrationBloomFilter.contains(requestParam.getUsername())) {
            throw new ServiceException("该用户名已经存在");
        }
    }

    @Override
    public int getOrder() {
        return 10;
    }
}
